package com.rd.teacher.jichao.day15.producer3;

import java.util.concurrent.ArrayBlockingQueue;

public class Consumer implements Runnable{
    ArrayBlockingQueue<Integer> queue;

    public Consumer(ArrayBlockingQueue<Integer> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
                if (queue.size() == 0) {
                    System.out.println("empty,waiting");
                }
                int value = queue.take();
                System.out.println(Thread.currentThread().getName()
                        + " take " + value);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
